<template>
  <page-meta :page-style="$theme.pageStyle">
    <!-- #ifndef H5 -->
    <navigation-bar :front-color="$theme.navColor" :background-color="$theme.navBgColor" />
    <!-- #endif -->
  </page-meta>
  <!-- :style="{backgroundImage: `url(${$domain}/static/icons/matchmaker/posterBg.png)`}" -->
  <view class="index">

    <!--顶部-->
    <u-navbar :safeAreaInsetTop="false" :placeholder="false" :is-back="true" :is-fixed="true"
      :backIconColor="titleColor" :title="'置顶套餐'" :border-bottom="false" :title-bold="true" :title-color="titleColor"
      :background="{ background: navBg }">
    </u-navbar>

    <view>
      <view class="page-reward">
        <view class="reward-top">
          <view class="top-title">
            温馨提示
          </view>
          <view class="top-text mt-[10rpx]" style="width: 100%">
            优先排序再最前面，吸引更多关注，增加相亲成功率
          </view>
        </view>
        <view class="page-box reward-box">
          <view class="box-title">
            请选择您的置顶套餐
          </view>
          <view class="box-package">
            <view class="package-item" @click="choseItem(item, index)" :class="{ active: listIndex == index }"
              v-for="(item, index) in listData.lists" :key="index">
              <view class="item-text">
                {{ item.title }}
              </view>
              <view class="item-money">
                <view class="money-text">
                  ¥
                </view>
                <view class="money-munber">
                  {{ item.money }}
                </view>
              </view>
            </view>
          </view>
        </view>
      </view>

      <view class="page-bottom">
        <view class="bottom-total">
          <view class="total-text">
            合计：
          </view>
          <view class="total-number">
            ¥ {{ listData.lists[listIndex].money }}
          </view>
        </view>
        <view class="bottom-btn" @click="submitForm">
          提交
        </view>
      </view>
      <view class="page-bottomFooter"></view>
    </view>


  </view>
</template>

<script>
import { getQxPackageListApi, getZdPackageListApi, payQxApi, payZdApi } from "@/api/new";
import { goPay } from "@/utils/goPay";

export default {
  data() {
    return {
      navBg: 'rgba(255,255,255,0)',
      titleColor: '#fff',
      listData: { lists: [{}] },
      listIndex: 0,
      terminal: 1,
      data: null
    };
  },
  onPageScroll(event) {
    this.navBg = event.scrollTop > 10 ? '#fff' : 'rgba(255,255,255,0)';
    this.titleColor = event.scrollTop > 10 ? '#111' : '#fff';
  },
  created() {
    // #ifdef MP-WEIXIN
    this.terminal = 1;
    // #endif
    // #ifdef H5
    this.terminal = 2;
    // #endif
    this.getQxPackageList();
  },
  methods: {
    navChange(item) {
      console.log('item', item);
    },
    navTo(url) {
      uni.navigateTo({ url });
    },
    async getQxPackageList() {
      this.listData = await getZdPackageListApi({
        page_no: 1,
        page_size: 200
      });
    },
    choseItem(item, index) {
      this.listIndex = index;
    },
    async submitForm() {
      this.data = await payZdApi({
        terminal: this.terminal,
        package_id: this.listData.lists[this.listIndex].id,
      });
      const payBack = await goPay(this.data.config);
      if (payBack && payBack.errMsg == 'requestPayment:ok') {
        uni.showToast({
          title: '支付成功',
          icon: 'none'
        });
        uni.redirectTo({
          url: '/packagesA/pages/myPullTheWire/myPullTheWire'
        });
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.index {
  padding-bottom: 60rpx;
  padding-top: 60rpx;
  position: relative;
  background-repeat: no-repeat;
  background-size: cover;
  overflow: hidden;
  width: 100%;
  transition: all 1s;
  min-height: calc(100vh - env(safe-area-inset-bottom));
  background: linear-gradient(181deg, #FF4DCA 0%, #CF68FF 25%, #FF4DD8 80%, #FF4DCA 100%);
}

.page-data {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20rpx;
  padding: 30rpx;

  .data-item {
    text-align: center;
    font-size: 28rpx;
    color: #ffffff;

    .item-number {
      font-size: 34rpx;
      font-weight: bold;
      color: #ffffff;
    }
  }
}

.page-reward {
  width: calc(100% - 60rpx);
  margin: 0 auto;

  .reward-top {
    padding: 20rpx 20rpx 50rpx 20rpx;
    color: #000;
    font-size: 24rpx;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    background-color: #fff;
    border-radius: 30rpx 30rpx 0 0;
    margin-bottom: -30rpx;
    flex-wrap: wrap;

    .top-icon {
      width: 28rpx;
      height: 28rpx;
      margin-right: 10rpx;
    }

    .top-title {
      font-size: 30rpx;
      font-weight: bold;
    }
  }

  .reward-box {
    margin-top: 0;

    .box-top {
      .top-list {
        display: flex;
        align-items: center;
        justify-content: flex-end;

        .list-btn {
          padding: 6rpx 20rpx;
          background: #F1F8FF;
          color: var(--color-primary);
          font-size: 28rpx;
          border-radius: 40rpx;
          margin-left: 20rpx;
        }

        .active {
          color: #ffffff;
          background: linear-gradient(to right, var(--color-primary), var(--color-minor));
        }
      }
    }

    .box-search {
      border: 1rpx solid #5BA3F5;
      width: 100%;
      padding: 15rpx 30rpx;
      border-radius: 40rpx;
      background-color: #ffffff;
      display: flex;
      align-items: center;
      justify-content: space-between;

      .search-input {
        width: 100%;
      }

      .search-icon {
        flex-shrink: 0;
      }
    }

    .box-list {
      margin-top: 30rpx;
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      gap: 20rpx;

      .list-child {
        padding: 20rpx;
        display: flex;
        align-items: center;
        justify-content: flex-start;
        font-size: 24rpx;
        color: #111111;
        background-color: #F3F8FE;
        border-radius: 30rpx;
        font-weight: bold;

        .child-pic {
          width: 70rpx;
          height: 70rpx;
          border-radius: 50%;
          margin-right: 20rpx;
          flex-shrink: 0;
        }

        .child-text {
          display: flex;
          align-items: center;
        }
      }

      .child-money {
        color: var(--color-primary);
      }
    }

    .box-title {
      text-align: center;
      font-size: 36rpx;
      color: #111111;
      font-weight: bold;
    }

    .box-package {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      gap: 20rpx;
      color: var(--color-primary);
      font-size: 28rpx;
      margin-top: 30rpx;

      .package-item {

        border-radius: 30rpx;
        text-align: center;
        background-color: #f1f1f1;

        .item-text {
          padding: 30rpx 10rpx 0;
          color: #000;
        }

        .item-money {
          padding: 15rpx 10rpx 30rpx;
          display: flex;
          align-items: flex-end;
          justify-content: center;
          font-weight: bold;
          color: #FF1212;

          .money-munber {
            font-size: 40rpx;
            margin-bottom: -4rpx;
            margin-left: 10rpx;
          }
        }
      }

      .active {
        background-color: #fff0fe;
        border-radius: 12px 12px 12px 12px;

        border: 1px solid #e65aeb;
        font-weight: bold;
      }
    }
  }
}

$color-primary: var(--color-primary); //var(--color-primary) 主色
$color-minor: var(--color-minor); //var(--color-minor) 副色


.page-item {
  margin: 20rpx auto;
  padding: 30rpx 20rpx;
  border-radius: 20rpx;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  background: linear-gradient(105deg, #F0F7FF 0%, #FAFCFF 56%);
  position: relative;

  .item-pic {
    width: 110rpx;
    height: 110rpx;
    border-radius: 50%;
    flex-shrink: 0;
  }

  .item-data {
    width: 100%;
    margin-left: 20rpx;

    .data-top {
      display: flex;
      align-items: center;

      .top-name {
        font-size: 36rpx;
        color: #111111;
        font-weight: bold;
      }

      .top-sex {
        transform: rotate(45deg);
        background-color: #FF668A;
        width: 30rpx;
        height: 30rpx;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        text-align: center;
        margin-left: 10rpx;
        margin-bottom: 10rpx;

        .sex-icon {
          display: inline-block;
          margin-left: 2rpx;
        }
      }

      .top-label {
        display: flex;
        align-items: center;
        justify-content: center;
        border: 2rpx solid #CCBBFF;
        padding: 4rpx 20rpx;
        border-radius: 40rpx;
        line-height: normal;
        font-size: 30rpx;
        transform: scale(0.8);

        .label-icon {
          width: 30rpx;
          height: 30rpx;
          margin-right: 10rpx;
        }
      }

    }

    .data-line {
      overflow: hidden;
      margin-top: 10rpx;
      display: flex;
      align-items: center;
      justify-content: flex-start;
      border-radius: 40rpx;
      font-size: 24rpx;
      color: #ffffff;
      position: relative;

      &:before {
        content: '';
        width: 100%;
        height: 100%;
        position: absolute;
        left: 0;
        top: 0;
        background-color: var(--color-primary);
        opacity: 0.1;
      }

      .line-left {
        flex-shrink: 0;
        border-radius: 40rpx 10rpx 70rpx 40rpx;
        padding: 4rpx 24rpx 4rpx 20rpx;
        background-image: linear-gradient(to right, $color-primary, $color-minor);
        margin-right: 20rpx;
        position: relative;
      }

      .line-right {
        color: $color-primary;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        max-width: 30%;
      }
    }

    .data-bottom {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-top: 20rpx;

      .bottom-user {
        display: flex;
        align-items: center;
        font-size: 24rpx;
        color: #999;

        .user-img {
          display: flex;
          align-items: center;
          flex-shrink: 0;
          margin-left: 15rpx;
          margin-right: 10rpx;

          .img-one {
            flex-shrink: 0;
            width: 50rpx;
            height: 50rpx;
            margin-left: -25rpx;
            border-radius: 50%;
            border: 2rpx solid #fff;
            box-shadow: 0 0 20rpx -10rpx rgba(0, 0, 0, 0.5);
          }
        }
      }

      .bottom-btn {
        width: 50%;
        padding: 10rpx 30rpx;
        background-image: linear-gradient(to right, $color-primary, $color-minor);
        position: relative;
        overflow: hidden;
        font-size: 28rpx;
        color: #ffffff;
        font-weight: bold;
        border-radius: 80rpx;

        .btn-pic {
          width: 100rpx;
          height: 100rpx;
          position: absolute;
          left: 0;
          top: 0;
          transform: translateX(-20%);
        }
      }
    }

    .data-id {
      color: #999999;
      font-size: 24rpx;
    }
  }

  .item-type {
    padding: 10rpx 30rpx;
    background-color: rgba(0, 0, 0, 0.03);
    border-radius: 20rpx 0 20rpx 0;
    font-size: 24rpx;
    color: var(--color-primary);
    position: absolute;
    bottom: 0;
    right: 0;
  }
}

.page-bottom {
  width: 100%;
  padding: 30rpx 30rpx calc(30rpx + env(safe-area-inset-bottom));
  position: fixed;
  bottom: 0;
  z-index: 2;
  background-color: #ffffff;
  box-shadow: 0 2px 7px 0 rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: space-between;

  .bottom-total {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    font-size: 30rpx;
    font-weight: bold;
    color: #111111;
    margin-right: 50rpx;
    flex-shrink: 0;

    .total-number {
      // color: var(--color-primary);
      color: #FF1212;
    }
  }

  .bottom-btn {
    width: 100%;
    height: 80rpx;
    line-height: 80rpx;
    text-align: center;
    background-image: linear-gradient(to right, var(--color-primary), var(--color-minor));
    color: #ffffff;
    font-size: 30rpx;
    font-weight: bold;
    border-radius: 40rpx;
  }

  &Footer {
    height: calc(140rpx + env(safe-area-inset-bottom));
  }
}
</style>
